import { _decorator, Color, Component, Material, Node, Sprite, SpriteFrame, SpriteRenderer } from 'cc';
import { delay } from './Util/AsyncUtils';
const { ccclass, property } = _decorator;

@ccclass('EntityFX')
export class EntityFX extends Component {
    @property(Material) hitMat: Material = null;
    originalMat: Material = null;
    sp: Sprite = null
    protected onLoad(): void {
        this.sp = this.node.getComponentInChildren(Sprite);
        this.originalMat = this.sp.getSharedMaterial(0);
    }
    start() {
        
    }

    async FlashFX() {
        this.sp.setSharedMaterial(this.hitMat, 0);
        await delay(200);
        this.sp.setSharedMaterial(this.originalMat, 0);
    }

    RedColorBlink() :void{
        if(this.sp.color.equals(Color.WHITE)){
            this.sp.color = Color.RED;
        }else{
            this.sp.color = Color.WHITE;
        }
    }
    CancelRedBlink(){
        this.unschedule(this.RedColorBlink);
        this.sp.color = Color.WHITE;
    }
}


